package com.link.play.fit.ai.ui.main.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter

class HomeChildAdapter(
    fragmentManager: FragmentManager, lifecycle: Lifecycle,val fragmentList:List<Fragment>
) : FragmentStateAdapter(fragmentManager, lifecycle) {

//    private val fragmentClasses = arrayOf(
//        HomeChildFragment1::class.java,
//        HomeChildFragment2::class.java,
//    )


    override fun getItemCount(): Int = fragmentList.size

    override fun createFragment(position: Int): Fragment {
//        val fragment: Class<*> = fragmentList[position]
        val fragment: Fragment = fragmentList[position]

        return try {
            fragment
        } catch (e: IllegalAccessException) {
            throw RuntimeException(e)
        } catch (e: InstantiationException) {
            throw RuntimeException(e)
        }
    }

}
